package com.more.spring.boot.springmybatisdemo.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.web.servlet.config.annotation.ContentNegotiationConfigurer;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

import java.util.List;

@Configuration
@EnableWebMvc //启动mvc
@ComponentScan(basePackages = "com.more.spring.boot.springmybatisdemo") //扫描组件
public class WebConfig implements WebMvcConfigurer {

    /*@Bean
    public InternalResourceViewResolver viewResolver() {
        InternalResourceViewResolver resolver = new InternalResourceViewResolver();
        resolver.setPrefix("/WEB-INF/views/");
        resolver.setSuffix(".jsp");
        return resolver;
    }*/

/*   @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/*") //允许跨域的路径
                .allowedOrigins("http://localhost:8080")//允许的源
                .allowedMethods("GET", "POST", "PUT", "DELETE")//允许的方法
                .allowedHeaders("*")//允许请求头
                .allowCredentials(true);//允许携带证件
    }*/

//    @Override
//    public void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
//        converters.add(new MappingJackson2HttpMessageConverter()); // 支持 JSON
//        converters.add(new MappingJackson2XmlHttpMessageConverter()); // 支持 XML
//    }

   /* @Override
    public void configureContentNegotiation(ContentNegotiationConfigurer configurer) {
        configurer.defaultContentType(MediaType.APPLICATION_JSON); // 默认返回 JSON
    }*/
}
